package co.com.services.institucion;

import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import co.com.smart.maestro.infraestructure.dto.InstitucionDTO;
import co.com.smart.session.DelegateContextEJB;


@Path("/SmartInstitucionServices")
public class InstitucionServices {
	@GET
	@Path("/getAllInstitucion")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getInstitucion() throws NamingException {
		return Response.ok(DelegateContextEJB.getInstitucionBeanLocal().consultarAllInstitucion())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@POST
	@Path("/getInstitucionId")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getInstitucionId(InstitucionDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getInstitucionBeanLocal().consultarInstitucionId(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/setInstitucion")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setInstitucion( InstitucionDTO json){ 
		return Response.ok(DelegateContextEJB.getInstitucionBeanLocal().insertarInstitucion(json))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}

	@PUT
	@Path("/editInstitucion")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setEditInstitucion(InstitucionDTO json){ 
		return Response.ok(DelegateContextEJB.getInstitucionBeanLocal().editInstitucion(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/removeInstitucion")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setRemoveInstitucion(InstitucionDTO json){ 
		return Response.ok(DelegateContextEJB.getInstitucionBeanLocal().removeInstitucion(json, true))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

}
